<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改公告类型')" />
</head>
<body class="white-bg">
<!--
    th:object 用于从作用域获取一个对象，该标签需要和th:field联动使用
        th:field必须在th:object所在标签的内部使用
        th:field用于从当前对象获取属性的值  不需要使用${对象.属性} ，
        而可以直接使用*{属性名}即可
-->
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-post-edit" th:object="${CmsType}">
        <input id="typeId" name="typeId" type="hidden" th:field="*{typeId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">公告类型名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="typeName" id="typeName" th:field="*{typeName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">公告类型描述：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="typeDesc" id="typeDesc" th:field="*{typeDesc}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">显示顺序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="typeSort" id="typeSort" th:field="*{typeSort}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" name="remark" class="form-control">[[*{remark}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "cms/type";

    $("#form-post-edit").validate({
        onkeyup: false,
        rules:{
            typeName:{
                remote: {
                    url: prefix + "/checkTypeNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "typeId" : function () {
                            return $.common.trim($("#typeId").val())
                        },
                        "typeName" : function() {
                            return $.common.trim($("#typeName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            typeSort:{
                digits:true
            },
        },
        messages: {
            "typeName": {
                remote: "公告类型名称已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-post-edit').serialize());
        }
    }
</script>
</body>
</html>